package com.example.dc.mapper;

import com.example.dc.domain.User;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * 用户接口类
 */
@Mapper
public interface UserMapper {
    @Select("select user_info_id id,password from d_user_auth where phone=#{account} or email=#{account}")
    public List<User> findPassword(@Param("account") String account);

    public void requestCode(@Param("account") String account,@Param("code") String  code,@Param("type") Character type);

    @Select("select count(*)>0 from d_code where account=#{account} and code=#{code} and request_time>=NOW()- INTERVAL 5 minute")
    public boolean codeIsRight(@Param("account") String account,@Param("code") String code);

    @Insert("insert into d_login_history (account,password,login_ip,type,status) values (#{account},#{password},#{address},#{type},#{status});")
    public void insertLoginHistory(@Param("account") String account,@Param("password") String password,@Param("address") String address,@Param("type") Character type,@Param("status") Character status);

    public User getUserInfoByUserId(@Param("userId") Integer userId);
    public User getUserInfoByAccount(@Param("account") String account);
    public List<User> getTeamAndUser(@Param("teamId") Integer teamId);

    @Select("select max(id) from d_user_info")
    public Integer getMax();

    @Insert("insert into d_user_info (nickname) values (#{nickname})")
    public void insertUserInfo(@Param("nickname") String nickname);

    @Select("select count(1) from d_user_auth where phone=#{phone}")
    public Integer findUser(@Param("phone") String phone);


    public void register(@Param("userId") Integer userId,@Param("account") String account,@Param("password") String password,@Param("type") Character type);

    @Update("update d_user_auth set user_name=#{name},age=#{age},sex=#{sex} where user_info_id=#{userId}")
    void updateUserAuth(@Param("userId") Integer userId,@Param("name") String name, @Param("age") Integer age, @Param("sex") Character sex);

    @Select("select count(*) from d_user_auth where user_info_id=#{userId} and create_time is not null")
    Boolean isFirst(@Param("userId") Integer userId);

    @Update("update d_user_auth set create_time=NOW() where user_info_id=#{userId}")
    void updateRegistTime(@Param("userId") Integer userId);

    void updateUserInfo(@Param("nickname") String nickname,@Param("avatar") String avatar,@Param("intro") String intro,@Param("userId") Integer userId);

    @Update("update d_user_auth set phone=#{phone},sex=#{sex},birthday=#{birthday},location=#{location},industry=#{industry},`like`=#{like} where user_info_id=#{userId}")
    void editUserAuth(@Param("userId") Integer userId,@Param("phone") String phone,@Param("sex") Character sex,@Param("birthday") String birthday,@Param("location") String location,@Param("industry") String industry,@Param("like") String like);

    @Update("update d_user_info set nickname=#{nickname},avatar=#{avatar},intro=#{intro} where id=#{userId}")
    void editUserInfo(@Param("userId") Integer userId,@Param("nickname") String nickname,@Param("avatar") String avatar,@Param("intro") String intro);
}
